package org.kimoji.operate;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.stereotype.Repository;

@Repository
public class OperateDAO {

	@Autowired
	private RedisTemplate<String, Object> redisTemplate;
	
	private static final String SUPPORT = "support:";
	private static final String COLLECTION = "collection:";
	private static final String ATTENTION = "attention:";
	
//	public void collect(String userId,){
//		redisTemplate.opsForHash().("", arg1, arg2);
//	}
	
	/**
	 * 專輯關注
	 * <strong>Description</strong>:
	 * @param userId
	 * @param albumId
	 * @param iv
	 * @return void
	 * @author chok
	 * 2014-2-3
	 */
	public void attent(String userId,String albumId,long iv){
		if(iv > 0)
			redisTemplate.opsForSet().add(ATTENTION + userId, albumId);//關注
		else
			redisTemplate.opsForSet().remove(ATTENTION + userId, albumId);//取消關注
		redisTemplate.opsForHash().increment(ATTENTION, albumId, iv);//對應專輯關注計數
	}
	
	/**
	 * 作品點贊
	 * <strong>Description</strong>:
	 * @param userId
	 * @param itemId
	 * @param iv
	 * @return void
	 * @author chok
	 * 2014-2-3
	 */
	public void support(String userId,String itemId,long iv){
		if(iv > 0)
			redisTemplate.opsForSet().add(SUPPORT + userId, itemId);//點贊
		else
			redisTemplate.opsForSet().remove(SUPPORT + userId, itemId);//取消點贊
		redisTemplate.opsForHash().increment(SUPPORT, itemId, iv);//對應作品點贊計數
	}
	
}
